/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.goods.web.controller.manager;

import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.goods.api.model.vo.manager.ProductSpecVo;
import com.medusa.gruul.goods.api.model.vo.manager.ProductSpecsAndSkusVo;
import com.medusa.gruul.goods.service.manager.IProductSpecService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品规格查询
 *
 * @author 张治保
 * date 2021/11/12
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/manager/product/{productId}/spec")
public class ProductSpecController {

    private final IProductSpecService productSpecService;

    @EscapeLogin
    @ApiOperation(value = "查询商品规格列表(树结构)")
    @GetMapping("/{specId}")
    public Result<List<ProductSpecVo>> get(
            @PathVariable @ApiParam(value = "商品id", required = true) Long productId,
            @PathVariable @ApiParam(value = "规格id,传0查询所有", required = true) Long specId
    ) {
        return Result.ok(
                productSpecService.getProductSpecs(productId, specId)
        );
    }

    @EscapeLogin
    @GetMapping("/specs-skus")
    @ApiOperation(value = "查询商品规格列表与Sku信息列表")
    public Result<ProductSpecsAndSkusVo> getSpecsAndSkusByProductId(@PathVariable @ApiParam(value = "商品id", required = true) Long productId) {
        return Result.ok(
                productSpecService.getSpecsAndSkusByProductId(productId)
        );
    }

    /*@Autowired
    private ProductController productController;
    //注意一下商品详情 购买后展示的详情的specs
    @EscapeLogin
    @GetMapping("/t")
    @ApiOperation(value = "测试",hidden = true)
    public Result<Void> testUpdate(){
        TenantContextHolder.setTenantId("8000088");
        ShopContextHolder.setShopId("800000000088");
        productController.updateProduct(UpdateProduct.get());
        return Result.ok();
    }

    @EscapeLogin
    @GetMapping("/tt")
    @ApiOperation(value = "测试",hidden = true)
    public Result<Void> testSave(){
        TenantContextHolder.setTenantId("8000088");
        ShopContextHolder.setShopId("800000000088");
        productController.issueProduct(IssueProduct.get());
        return Result.ok();
    }*/


}
